﻿using Direct.IDAL.User.Jurisdiction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectSell.Model.User;

namespace DirectSell.BLL.User.Jurisdiction
{
    /// <summary>
    /// 修改资料服务层
    /// </summary>
    public  class ModifyInfoService:UserService
    {
        #region 初始化数据--郭文昊--2018年10月29日11:40:14
        protected IModifyInfoRespository _modifyInfoRepository { get; set; }
        public ModifyInfoService(IModifyInfoRespository modifyInfoRepository)
        {
            this._modifyInfoRepository = modifyInfoRepository;
        }
        #endregion

        #region 修改资料入口--郭文昊--2018年10月29日11:49:44
        /// <summary>
        /// 修改资料入口
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="param"></param>
        /// <returns></returns>
        protected override async Task<UserRespCode> OperationAsync<T>(T param)
        {
            var info = param as UserInforMationDetails;
            //判断传入参数是否为空
            if (info == null)
            {
                return UserRespCode.传入参数不正确;
            }
            //判断二级密码
            if (!await _modifyInfoRepository.CheckSecondPassword(info.UserCode, info.UserSecondPassWord))
            {
                return UserRespCode.二级密码输入错误;
            }
            //修改用户资料
            var result =  await Task.Run(() => { return _modifyInfoRepository.ModifyInfo(info); });

            if (!result)
            {
                return UserRespCode.失败;
            }
            return UserRespCode.成功;
        }
        #endregion

    }
}
